//
//  LoginDownView.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/11/17.
//  Copyright © 2016年 郑东喜. All rights reserved.
//  登陆页面下半部分uiview自定义

import UIKit

//代理
protocol LoginDownViewDelegate {
    ///微信代理事件
    func wxloginSEL()
    
    ///QQ代理事件
    func qqLoginSEL()
}


class LoginDownView: UIView {

    
    //设置代理监听按钮事件
    var delegate : LoginDownViewDelegate?

    override func layoutSubviews() {
//        self.backgroundColor = UIColor.gray
    
        // MARK:- 左边微信登陆视图
        self.leftView()
        // MARK:- 左边微信登陆视图
        self.rightView()
    }
}

// MARK:- 左边微信登陆视图
extension LoginDownView {
    func leftView() -> Void {
        //左边微信登陆视图
        let leftView = UIView(frame: CGRect(x: 0, y: 0, width: self.bounds.width * 0.5, height: self.bounds.height * 0.5))
        
//        leftView.backgroundColor = UIColor.red
        self.addSubview(leftView)
        
        //微信按钮
        let btnW = leftView.frame.size.width * 0.4
        
        
        let wxBtn = CenTitImg(frame: CGRect(x: leftView.frame.size.width * 0.6 - 25, y: leftView.frame.size.height * 0.6 - btnW * 0.5, width: btnW, height: btnW))
        
        wxBtn.setTitle("微信登陆", for: .normal)
        wxBtn.setImage(UIImage.init(named: "wx"), for: .normal)
        wxBtn.setImage(UIImage.init(named: "wx"), for: .highlighted)
        wxBtn.addTarget(self, action: #selector(LoginDownView.clickWXImgSEL), for: .touchUpInside)

        
        leftView.addSubview(wxBtn)
    }
}


// MARK:- 左边微信登陆视图
extension LoginDownView {
    func rightView() -> Void {
        //右边QQ登陆视图
        let rightView = UIView(frame: CGRect(x: self.bounds.width * 0.5, y: 0, width: self.bounds.width * 0.5, height: self.bounds.height * 0.5))
        
//        rightView.backgroundColor = UIColor.blue
        self.addSubview(rightView)
        
        //QQ按钮
        let btnW = rightView.frame.size.width * 0.4
        
        let qqBtn = CenTitImg(frame: CGRect(x: rightView.frame.size.width * 0.4 - btnW * 0.5, y: rightView.frame.size.height * 0.6 - btnW * 0.5, width: btnW, height: btnW))
        
        qqBtn.setTitle("QQ登陆", for: .normal)
        qqBtn.setImage(UIImage.init(named: "qq"), for: .normal)
        qqBtn.setImage(UIImage.init(named: "qq"), for: .highlighted)
        
        qqBtn.addTarget(self, action: #selector(LoginDownView.clickQQImgSEL), for: .touchUpInside)
        
        rightView.addSubview(qqBtn)

    }
}

// MARK:- 单机事件
extension LoginDownView {
    //微信
    func clickWXImgSEL() -> Void {
        print("微信")
        delegate?.wxloginSEL()
    }
    
    //QQ
    func clickQQImgSEL() -> Void {
        print("QQ")
        delegate?.qqLoginSEL()
    }
}




